using System;
using System.Collections.Generic;
using System.Text;

using System.Xml.XPath;
using System.Xml.Xsl;

namespace BadHabit.Factory.Reports {
    
    
    public class ProposalReport : Report {

        private string proposalUId;

        /// <summary>
        /// Implements a Report class to generate a proposal report.
        /// </summary>
        /// <param name="factory"></param>
        public ProposalReport(Factory factory, string proposalUId) : base(factory) {
            this.proposalUId = proposalUId;
        }

        /// <summary>
        /// The template type name.
        /// </summary>
        public override string TemplateTypeName {
            get {
                return "ProposalReport";
            }
        }


        public override System.Data.DataSet AdjustDataSet(System.Data.DataSet report) {
            
            report = base.AdjustDataSet(report);

            Data.ProjectDataSet project = (Data.ProjectDataSet)report;


            project.Project.Columns.Add("CurrentProposalUId", typeof(string));
            project.Project[0]["CurrentProposalUId"] = proposalUId;

            project.Project.Columns.Add("ProposalDate", typeof(string));
            project.Project[0]["ProposalDate"] = DateTime.Now.ToLongDateString();

            project.Project.Columns.Add("EstimatedEndDateString", typeof(string));
            project.Project[0]["EstimatedEndDateString"] = project.Project[0].EstimatedEndDate.ToShortDateString();
            project.Project.Columns.Add("EstimatedStartDateString", typeof(string));
            project.Project[0]["EstimatedStartDateString"] = project.Project[0].EstimatedStartDate.ToShortDateString();


            project.ProjectPayment.Columns.Add("PlannedPayDateString", typeof(System.String));
            foreach (Data.ProjectDataSet.ProjectPaymentRow r in project.ProjectPayment.Rows)
                r["PlannedPayDateString"] = r.PlannedPayDate.ToShortDateString();


            project.Project[0].MarkVisibleBacklogItemsForProposal(proposalUId);

            Data.ProjectDataSet.ProposalRow proposal = project.Proposal.FindByProposalUId(proposalUId);

            project.Proposal.Columns.Add("StartDateString", typeof(string));
            if(!proposal.IsStartDateNull())
                proposal["StartDateString"] = proposal.StartDate.ToShortDateString();

            project.Proposal.Columns.Add("EndDateString", typeof(string));
            if (!proposal.IsEndDateNull())
                proposal["EndDateString"] = proposal.EndDate.ToShortDateString();

            project.Proposal.Columns.Add("ApprovalDateString", typeof(string));
            if (!proposal.IsApprovalDateNull())
                proposal["ApprovalDateString"] = proposal.ApprovalDate.ToLongDateString();


            return project;
        }

    }
}
